<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.utils.SiteHelper" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="com.qipay.admin.withdraw.config.BwmConfig" %>
<!doctype html>
<html>
<head>
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/bootstrapValidator.min.css">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <div class="content-wrapper">
        <section class="content" >
            <div class="row">
                <div class="col-xs-12" style="border:0px solid red;">
                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title">提现|代付 申请</h3>
                        </div>
                        <%
                            UserLevel userLevel = (UserLevel) request.getAttribute("level");
                            String msg = (String) request.getAttribute("msg");
                        %>
                        </div>
                        <div class="box">
                            <div class="box-header with-border">
                                <h3 class="box-title">QQ
                                    (<span style="color: red;">
                                        余额：<%=request.getAttribute("QQAllBalance")%>&nbsp;&nbsp;；
                                        可用余额：<%=request.getAttribute("QQAllBrawableBalance")%>
                                    </span>)

                                    微信
                                    (<span id="banlance" style="color: red;">
                                            余额：<%=request.getAttribute("WxAllBalance")%>&nbsp;&nbsp;；
                                            可用余额：<%=request.getAttribute("WxAllBrawableBalance")%>
                                    </span>)
                                    <span style="color: red;">
                                            <%=msg==null?"":"(温馨提示："+msg+")"%>
                                    </span>
                                </h3>
                            </div>

                            <div class="box-body">
                                <form class="form-horizontal" action="/withdraw/anotherApply" method="POST" id="applyForm">
                                    <input id="agentNo" type="hidden" class="form-control" name="agentNo"
                                           value="<%=BwmConfig.agentNo%>">
                                    <input id="accountType" type="hidden" class="form-control" name="accountType"
                                           value="<%=BwmConfig.accountType_Default%>">

                                    <label class="col-sm-2" for="source">通道</label>
                                    <div class="form-group col-sm-10">
                                        <select id="source" name="source"  class="form-control">
                                            <option value="WEIXIN">微信扫码</option>
                                            <option value="QQ">QQ扫码</option>
                                        </select>
                                    </div>

                                    <label class="col-sm-2" for="amount">金额</label>
                                    <div class="form-group col-sm-10"><input type="number" class="form-control"
                                                                             id="amount" name="amount"
                                                                             value="0">
                                    </div>
                                    <label class="col-sm-2" for="banks">银行</label>
                                    <div class="form-group col-sm-10">
                                        <select id="banks" name="bankCode"  class="form-control">
                                            <option value="CMB">招商银行</option>
                                            <option value="ICBC">中国工商银行</option>
                                            <option value="CCB">中国建设银行</option>
                                            <option value="SPDB">浦发银行</option>
                                            <option value="ABC">中国农业银行</option>
                                            <option value="BOC">中国银行</option>
                                            <option value="CMBC">中国民生银行</option>
                                            <option value="PAB">平安银行</option>
                                            <option value="CIB">兴业银行</option>
                                            <option value="BCOM">交通银行</option>
                                            <option value="CITIC">中信银行</option>
                                            <option value="CEB">中国光大银行</option>
                                            <option value="HXB">华夏银行</option>
                                            <option value="CMBC">中国银行</option>
                                            <option value="CGB">广发银行</option>
                                            <option value="PSBC">邮政储蓄银行</option>
                                        </select>
                                    </div>


                                    <label class="col-sm-2" for="accNo">卡号</label>
                                    <div class="form-group col-sm-10"><input type="text" class="form-control"
                                                                             id="accNo"
                                                                             name="accNo"
                                                                             value="">

                                    </div>

                                    <label class="col-sm-2" for="accName">开户人姓名</label>
                                    <div class="form-group col-sm-10"><input type="text" class="form-control"
                                                                             id="accName"
                                                                             name="accName"placeholder="开户人姓名"
                                                                             value="">
                                    </div>


                                    <label hidden class="col-sm-2" for="mobile"></label>
                                    <div hidden class="form-group col-sm-10"><input type="text" class="form-control"
                                                                                    data-inputmask='mask": "99999999999"'
                                                                                    id="mobile"
                                                                                    name="mobile"
                                                                                    value="">
                                    </div>
                                    <label class="col-sm-2" for="mobile">手机校验码</label>
                                    <div class="form-group  col-sm-10">
                                        <input type="text" class="form-control"
                                               id="validCode"
                                               name="validCode"
                                               value="">
                                        <div class="input-group-btn">
                                            <button id="sendValid" type="button"
                                                    class="btn btn-info btn-flat btn-warning">发送校验码
                                            </button>
                                        </div>
                                    </div>


                                    <div class="box-footer">
                                        <button type="button" class="btn btn-default" onclick="window.history.back()">
                                            返回
                                        </button>
                                        <%
                                            if(userLevel.getCode()==1000){%>
                                                <button type="submit" class="btn btn-primary" id="btnSubmit">提交</button>
                                        <%}
                                        %>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>


                </div>
        </section>
    </div>
    <jsp:include page="foot.jsp"></jsp:include>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/icheck.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/bootstrapValidator.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/business/withdraw_apply.js?v=<%= request.getAttribute("StaticVersion") %>"></script>
<script type="text/javascript">
    $(function () {

        // init.args
        var operation = $("#operation_tab li.active").attr("key");
        var password = $("#password").val();
        var min = Number($("#minVal").val());
        var max = Number($("#maxVal").val());
        console.log(min);
        console.log($("#maxVal").val() + "= " + max);
        var start = $("#start").val();
        var end = $("#end").val();
        var code = "";
        type = $(".tab-content div.active .type").find("option:selected").attr("type");

        // init.fill
        $("#type").val(type);
        $("#operation").val(operation);
        $("#operationName").val($("#operation_tab li.active a").text());
        //initAmount();

        // init.validator
        $('#applyForm').bootstrapValidator({
            framework: 'bootstrap',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                operationName: {
                    validators: {
                        notEmpty: {
                            message: '操作类型不能为空'
                        }, callback: {
                            message: '提现申请时间为 ' + start + '-' + end + ',请至有效时间后刷新界面重试',
                            callback: function (value, validator) {
                                return checkTime();
                            }
                        }
                    }
                },
                fee: {
                    validators: {
                        notEmpty: {
                            message: '扣费金额不能为空'
                        }
                    }
                },
                actualAmount: {
                    validators: {
                        notEmpty: {
                            message: '实际到账金额不能为空'
                        }
                    }
                },
                bankName: {
                    validators: {
                        notEmpty: {
                            message: '银行名称不能为空'
                        }
                    }
                },
                cardNo: {
                    validators: {
                        notEmpty: {
                            message: '卡号不能为空'
                        }, stringLength: {
                            min: 16,
                            max: 19,
                            message: '银行卡位数有误'
                        },
                    }
                },
                idCardNo: {
                    validators: {
                        notEmpty: {
                            message: '身份证号不能为空'
                        }, stringLength: {
                            min: 17,
                            max: 18,
                            message: '身份证号输入有误'
                        },
                    }
                },
                payerName: {
                    validators: {
                        notEmpty: {
                            message: '姓名不能为空'
                        }
                    }
                },
                phoneNumber: {
                    validators: {
                        notEmpty: {
                            message: '银行预留手机号不能为空'
                        },
                        regexp: {
                            regexp: /^[0-9]{11}$/,
                            message: '手机号位数有误'
                        }
                    }
                },
                validCode: {
                    validators: {
                        notEmpty: {
                            message: '手机校验码不能为空'
                        },
                        callback: {
                            message: '手机校验码错误',
                            callback: function (value, validator) {
                                return code == value;
                            }
                        },
                    }
                },
                withdrawPassword: {
                    validators: {
                        notEmpty: {
                            message: '提现密码不能为空'
                        },
                        callback: {
                            message: '提现密码错误',
                            callback: function (value, validator) {
                                alert(value+"=="+password);
                                return password == value;
                            }
                        },
                    },
                    regexp: {
                        regexp: /^[0-9]{6}$/,
                        message: '提现密码位数有误'
                    }
                },
            }
        });

        // sms
        $("#sendValid").click(function () {
            // disable
            var limit = 60;
            $("#sendValid").attr("disabled", true);
            var timer = setInterval(function () {
                if (--limit != 0) {
                    console.log(limit)
                    $("#sendValid").text(limit + "秒后重发");
                } else {
                    console.log("60s pass")
                    $("#sendValid").text("发送校验码");
                    $("#sendValid").attr("disabled", false);
                    clearInterval(timer);
                }
            }, 1000);

            // request
            $.get("/withdraw/valid", function (data) {
                if (null != data && data.code == 200) {
                    code = data.data;
                } else {
                    console.log("get fail")
                    clearInterval(timer);
                    $("#sendValid").attr("disabled", false);
                    $("#sendValid").text("发送校验码");
                    alert("失败:" + data.msg);
                }
            }).fail(function () {
                console.log("get request fail")
                clearInterval(timer);
                $("#sendValid").attr("disabled", false);
                $("#sendValid").text("发送校验码");
            });
        });
    });


    function checkTime() {

        // curTime
        var date = new Date();
        var start = $("#start").val();
        var end = $("#end").val();
        var curTime = date.getHours() * 100 + date.getMinutes();
        var startLimit = parseFloat(start.replace(":", ""));
        var endLimit = parseFloat(end.replace(":", ""));

        // check
        return curTime > startLimit && curTime < endLimit
    }
</script>
</body>
</html>

